clear

set scheme plotplain

use Data_Proc\recs_clean

keep if recs==2020 | recs==2009
keep if heat==1
keep if vintage<=2000


********************************************************
* CROSS-SECTIONAL GRAPHS
********************************************************
egen tag = tag(domain)

gen names = "CT,ME,NH,RI,VT" if reportable_domain =="Connecticut, Maine, New Hampshire, Rhode Island, Vermont"
replace names = "MA" if reportable_domain =="Massachusetts"
replace names = "NY" if reportable_domain =="New York"
replace names = "NJ" if reportable_domain =="New Jersey"
replace names = "PA" if reportable_domain =="Pennsylvania"
replace names = "IL" if reportable_domain =="Illinois"
replace names = "IN,OH" if reportable_domain =="Indiana, Ohio"
replace names = "MI" if reportable_domain =="Michigan"
replace names = "WI" if reportable_domain =="Wisconsin"
replace names = "IA,MN,ND,SD" if reportable_domain =="Iowa, Minnesota, North Dakota, South Dakota"
replace names = "KS,NE" if reportable_domain =="Kansas, Nebraska"
replace names = "MO" if reportable_domain =="Missouri"
replace names = "VA" if reportable_domain =="Virginia"
replace names = "DE,DC,MD,WV" if reportable_domain =="Delaware, District of Columbia, Maryland, West Virginia"
replace names = "GA" if reportable_domain =="Georgia"
replace names = "NC,SC" if reportable_domain =="North Carolina, South Carolina"
replace names = "FL" if reportable_domain =="Florida"
replace names = "AL,KY,MS" if reportable_domain =="Alabama, Kentucky, Mississippi"
replace names = "TN" if reportable_domain =="Tennessee"
replace names = "AR,LA,OK" if reportable_domain =="Arkansas, Louisiana, Oklahoma"
replace names = "TX" if reportable_domain =="Texas"
replace names = "CO" if reportable_domain =="Colorado"
replace names = "ID,MT,UT,WY" if reportable_domain =="Idaho, Montana, Utah, Wyoming"
replace names = "AZ" if reportable_domain =="Arizona"
replace names = "NV,NM" if reportable_domain =="Nevada, New Mexico"
replace names = "CA" if reportable_domain =="California"
replace names = "OR,WA" if reportable_domain =="Alaska, Hawaii, Oregon, Washington"
 
gen pos = 3
replace pos = 2 if reportable_domain =="Indiana, Ohio"
replace pos = 4 if reportable_domain =="Colorado"
replace pos = 11 if reportable_domain =="Illinois"
replace pos = 11 if reportable_domain =="Connecticut, Maine, New Hampshire, Rhode Island, Vermont"
replace pos = 6 if reportable_domain=="Kansas, Nebraska"

gen pos2 = 3
replace pos2 = 2 if reportable_domain =="Indiana, Ohio"
replace pos2 = 6 if reportable_domain=="Illinois"
replace pos2 = 2 if reportable_domain=="PA" | reportable_domain =="Nevada, New Mexico"
*replace pos2 = 6 if reportable_domain =="Colorado"
replace pos2 = 5 if reportable_domain=="Idaho, Montana, Utah, Wyoming" | reportable_domain =="Delaware, District of Columbia, Maryland, West Virginia"
replace pos2= 6 if reportable_domain=="Kansas, Nebraska"
replace pos2 = 11 if reportable_domain =="Connecticut, Maine, New Hampshire, Rhode Island, Vermont"

 * GRAPH FOR FULL SAMPLE
gen ybeta = 0
gen yhi = 0
gen ylo = 0
gen xcr = 0
foreach s of numlist 1/27 {
		qui: reg hp recs2020 if domain==`s' [pw=nweight]
		qui: replace ybeta = _b[recs2020] if domain==`s'
		qui: replace ylo = _b[recs2020] + 1.96*_se[recs2020] if domain==`s'
		qui: replace yhi = _b[recs2020] - 1.96*_se[recs2020] if domain==`s'
}
foreach s of numlist 1/27 {
		sum lncr if domain==`s' [iw=nweight]
		replace xcr = r(mean) if domain==`s'
}

reg ybeta xcr [pw=nweight] if recs==2020, cluster(domain)
predict ynewfit
twoway  (rspike ylo yhi xcr if tag==1, lcolor(gs13)) ///
		(scatter ybeta xcr if tag==1, ms(c) msize(tiny) mcolor(black) mlabel(names) mlabs(vsmall) mlabv(pos)) ///
		(scatter ynewfit xcr if tag==1, c(l) ls(solid) lwidth(thin) ms(none) ///
			ytitle("Heat pump replacement") xtitle("Relative energy cost (other fuel vs. heat pump)") legend(off) xlabel(-.4(.2).6))
graph export Final_Output\fig_CostScatterOld_Update.png, as(png) replace
drop ybeta yhi ylo xcr ynewfit


* GRAPH OMITTING COVID (EQUIPMENT AGE < 2)
gen ybeta = 0
gen yhi = 0
gen ylo = 0
gen xcr = 0
foreach s of numlist 1/27 {
		qui: reg hp recs2020 if domain==`s' & age>0 [pw=nweight]
		qui: replace ybeta = _b[recs2020] if domain==`s'
		qui: replace ylo = _b[recs2020] + 1.96*_se[recs2020] if domain==`s'
		qui: replace yhi = _b[recs2020] - 1.96*_se[recs2020] if domain==`s'
}
foreach s of numlist 1/27 {
		sum lncr if domain==`s' [iw=nweight]
		replace xcr = r(mean) if domain==`s'
}

reg ybeta xcr [pw=nweight] if recs==2020, cluster(domain)
predict ynewfit
twoway  (rspike ylo yhi xcr if tag==1, lcolor(gs13)) ///
		(scatter ybeta xcr if tag==1, ms(c) msize(tiny) mcolor(black) mlabel(names) mlabs(vsmall) mlabv(pos2)) ///
		(scatter ynewfit xcr if tag==1, c(l) ls(solid) lwidth(thin) ms(none) ///
			ytitle("Heat pump replacement") xtitle("Relative energy cost (other fuel vs. heat pump)") legend(off) xlabel(-.4(.2).6))
drop ybeta yhi ylo xcr ynewfit
graph export Final_Output\fig_CostScatterOld_NoCovid_Update.png, as(png) replace


clear
exit




